How do you convert an unsigned int[16] of hexidecimal to an unsigned char array without losing any information?

Posted by user1068636 on Stack Overflow See other posts from Stack Overflow or by user1068636
Published on 2012-09-09T20:52:21Z Indexed on 2012/09/09 21:38 UTC
Read the original article Hit count: 185

Filed under:
|
|

I have a unsigned int[16] array that when printed out looks like this:

4418703544ED3F688AC208F53343AA59

The code used to print it out is this:

for (i = 0; i < 16; i++)
    printf("%X", CipherBlock[i] / 16), printf("%X",CipherBlock[i] % 16);
printf("\n");

I need to pass this unsigned int array "CipherBlock" into a decrypt() method that only takes unsigned char *. How do correctly memcpy everything from the "CipherBlock" array into an unsigned char array without losing information?

My understanding is an unsigned int is 4 bytes and unsigned char 1 byte. Since "CipherBlock" is 16 unsigned integers, the total size in bytes = 16 * 4 = 64 bytes. Does this mean my unsigned char[] array needs to be 64 in length?

If so, would the following work?

unsigned char arr[64] = { '\0' };
memcpy(arr,CipherBlock,64); 

This does not seem to work. For some reason it only copies the the first byte of "CipherBlock" into "arr". The rest of "arr" is '\0' thereafter.

© Stack Overflow or respective owner

Related posts about c

    Related posts about byte